import { getSearchTop, getSearchResult } from "@/services";
import { defineStore } from "pinia";

const useSearchStore = defineStore("search", {
  state: () => ({
    topList: [],
    resultList: [],
    hotFilters: [],
    list: []
  }),
  actions: {
    async fetchSearchTop() {
      const res = await getSearchTop()
      this.topList = res.data.data.allConditions.map(item => {
        return {
          ...item,
          value: 4,
          activeIndex: 0
        }
      })
      console.log(this.topList);
    },
    async fetchSearchResult() {
      const res = await getSearchResult()
      this.resultList = res.data.data.items
      this.hotFilters = res.data.data.hotFilters
    },
    async fetchSearch() {
      const res = await getSearchTop()
      this.list = res.data.data.allConditions[0].subGroups.filter(item=>item.items.length>0).map(item=>{
        return {
          ...item,
          isShow:false
        }
      })
      console.log(this.list);
    },
  }
})

export default useSearchStore
